// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Title.java

package com.java4less.rchart;

import com.java4less.rchart.gc.ChartColor;
import com.java4less.rchart.gc.ChartFont;
import com.java4less.rchart.gc.ChartGraphics;
import com.java4less.rchart.gc.GraphicsProvider;

// Referenced classes of package com.java4less.rchart:
//			ChartComponent, ChartLabel

public class Title extends ChartComponent
{

	public String text;
	public ChartFont font;
	public ChartColor color;

	public Title(String t)
	{
		font = GraphicsProvider.getFont("Arial", ChartFont.PLAIN, 14);
		color = GraphicsProvider.getColor(ChartColor.BLACK);
		text = t;
	}

	public void draw(ChartGraphics g)
	{
		g.setColor(color);
		g.setFont(font);
		if (text.indexOf("@") >= 0)
		{
			ChartLabel formattedLabel = new ChartLabel(text, "", false, true);
			formattedLabel.initialize(g, chart);
			formattedLabel.paint(g, x, y, width, height);
			return;
		}
		String txt[] = new String[3];
		txt[0] = text;
		if (txt[0].indexOf("\\n") > -1)
		{
			txt[1] = txt[0].substring(txt[0].indexOf("\\n") + 2, txt[0].length());
			txt[0] = txt[0].substring(0, txt[0].indexOf("\\n"));
			if (txt[1].indexOf("\\n") > -1)
			{
				txt[2] = txt[1].substring(txt[1].indexOf("\\n") + 2, txt[1].length());
				txt[1] = txt[1].substring(0, txt[1].indexOf("\\n"));
			}
		}
		for (int i = 0; i < 3; i++)
		{
			if (txt[i] == null)
				continue;
			int toCenterX = (width - g.getFontWidth(null, txt[i])) / 2;
			if (toCenterX < 0)
				toCenterX = 0;
			int toCenterY = (height - g.getFontHeight()) / 2;
			if (toCenterY < 0)
				toCenterY = 0;
			g.drawString(txt[i], x + toCenterX, y + toCenterY + g.getFontHeight() * (i + 1));
		}

	}
}
